﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Warensoft.Socket;
using Warensoft.Socket.Extension;

namespace Warensoft.SocketImplementation
{
    public class Session:ClientSessionBase
    {
        //private ClientSocket socket;

        public Session(ClientSocket socket)
            : base(socket)
        {
            
        }
        public new WarensoftSocketServer Server
        {
            get
            {
                return base.Server as WarensoftSocketServer;
            }
        }
        public override void OnDisconnected()
        {
            try
            {
                this.Server.SessionPyLoader.CallbackObject.OnDisconnected(this);
            }
            catch (Exception ex)
            {
                this.OnErrorMessage(ex);
            }
        }

        public override void OnNewMessage(System.IO.MemoryStream message)
        {
            var server = this.Server as WarensoftSocketServer;
            try
            {              
                server.MessageLoader.CallbackObjectList[message.GetPackageName().ToString()].ExecuteMessage(this, server, message);
            }
            catch (Exception ex)
            {
                this.OnErrorMessage(ex); 
            }
        }
    }
}
